import { defineStore, createPinia } from 'pinia'
import { computed, ref } from 'vue'
import { App } from 'vue'
import 'element-plus/theme-chalk/el-message.css'

const pinia = createPinia()

// 封装路由初始化方法
export const initStore = (app: App<Element>) => {
  app.use(pinia)
}

// 在 Setup Store 中：
// ref() 就是 state 属性
// computed() 就是 getters
// function() 就是 actions

//
//
// 联网状态
export const useOnlineStatusStore = defineStore('onlineStatus', () => {
  const onlineStatus = ref<boolean>(true)
  const refresh = ref<string>()

  function setStatus(value: boolean) {
    onlineStatus.value = value
  }
  function getStatus() {
    return onlineStatus.value
  }

  // 给出联网情况提示变化
  function setRefresh() {
    refresh.value = new Date().toString()
  }

  return {
    onlineStatus: computed(() => onlineStatus.value),
    refresh: computed(() => refresh.value),
    setStatus,
    getStatus,
    setRefresh,
  }
})
